/*
 * Universidad del Valle de Guatemala
 * Departamento de Ciencias de la Computacion
 * Algoritmos y Estructuras de Datos
 * Hoja de Trabajo 5
 * David Coronado, 07325
 */

/**
 *
 * @author David Coronado
 */

import java.util.Vector;
import java.util.Comparator;

public class Heap_Implementation <E> implements Priority_Queue_Interface<E>, Comparator{

    private Vector<E> heap;

    /**
     * Constructor, instances the vector object
     */
    public Heap_Implementation(){
        heap = new Vector();
    }

    /**
     *
     * @param number added to the queue
     */
    public void add(E number) {
            heap.add(number);

    }

    /**
     *
     * @return the element with the highest priority
     */
    public E remove() {
        int max = 0;
        int index = 0;
        E returnvalue = null;
        int num;

        //Does the checkin of the max number in the vector (heap)
        for(int i=0 ; i<heap.size() ; i++){
            num = Integer.parseInt(heap.get(i)+"");
            if(num > max){
                index = i;
                max = num;
            }
        }
        
        returnvalue = heap.remove(index);

        return returnvalue;
    }

    /**
     *
     * @return true if the queue (vector) is empty
     */
    public boolean isEmpty() {
        return heap.isEmpty();
    }

    /**
     *
     * @param index of the element we wish to see
     */
    public void peek(int index){
        System.out.println(Integer.parseInt(heap.get(index)+""));
    }

   

    /**
     * compares two objects
     * @param o1, number 1
     * @param o2, number 2
     * @return an int between -1 and 1
     */
    public int compare(Object o1, Object o2) {
        int num1 = Integer.parseInt(o1+"");
        int num2 = Integer.parseInt(o2+"");

        if(num1 > num2)
            return 1;
        else
            if(num1 < num2)
                return -1;
            else
                return 0;
    }




}
